package org.xbzheng.restful_study.tool;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.ObjectUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/11/17.
 */
public class ArrayTool {

    public static Object[] intersection(Object[] obj1, Object[] obj2){
        List list = new ArrayList();
        if(ObjectTool.isEmpty(obj1) || ObjectTool.isEmpty(obj2)){
            return list.toArray();
        }
        for(Object obj : obj1){
            if(ArrayUtils.contains(obj2, obj)){
                list.add(obj);
            }
        }
        return list.toArray();
    }

    public static <T> T[] toArray(List<T> params){
        if(ObjectTool.isEmpty(params)){
            return null;
        }

        T[] t = (T[])new Object[params.size()];

        return params.toArray(t);
    }
}
